﻿using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.Web;
using System.IO;
using System.Reflection;

namespace ArchitectureV2
{
    public static class KnownTypes
    {
        #region Constants

        const string ModulesPath = @"C:\modules";
        //const string ModulesPath = @"E:\work\bc\project300\tfs\sociallearning\WCF\ArchitectureV2\bin";
        const string NewModulePath = @"C:\modules\new";

        #endregion

        #region Fields

        public static readonly ModuleLoader Modules;

        private static HashSet<Type> typeList;

        #endregion

        #region Constructor

        static KnownTypes()
        {
            typeList = new HashSet<Type>();
            ClearTypes();
            Debug.WriteLine("--- Start ---");
            Modules = new ModuleLoader();
            Modules.FindModulesInPath(ModulesPath);
        }

        #endregion

        #region Methods

        public static IEnumerable<Type> GetTypes(ICustomAttributeProvider provider)
        {
            Debug.WriteLine("Known types: " + typeList.Count);
            foreach (Type t in typeList)
            {
                Debug.WriteLine("  " + t.Name);
            }
            return (typeList);
        }

        public static void AddType(Type t)
        {
            typeList.Add(t);
            typeList.Add(typeof(List<>).MakeGenericType(t));
        }

        public static void ClearTypes()
        {
            typeList.Clear();
            typeList.Add(typeof(List<String>));
            typeList.Add(typeof(DateTime));
        }

        #endregion
    }

    static class Debug
    {
        public static void WriteLine(string x, params object[] parameters)
        {
            /*using (StreamWriter w = new StreamWriter("E:\\debug.txt", true))
            {
                w.WriteLine(x, parameters);
                w.Close();
            }*/
        }
    }
}